﻿Imports Controle
Imports UtilPadrao

Public Class frmTipoPA

#Region "Variáveis"
    Private objTIpoPA As New ctrTipoPA
#End Region

#Region "Métodos"

#End Region

#Region "Eventos"

    Private Sub frmTipoPA_alteraModo(ByVal eModoAtual As FronteiraPadrao.frmPadrao.eModo) Handles Me.alteraModo

        Me.txtDescricao.Enabled = Not (eModoAtual = eModo.eAguardando)
        Me.chkEspComplemento.Enabled = Not (eModoAtual = eModo.eAguardando)
        Me.btnSelecionarTipoPA.Enabled = (eModoAtual = eModo.eAguardando)
        Me.txtCodigo.Enabled = (eModoAtual = eModo.eAguardando)

    End Sub

    Private Sub frmTipoPA_carregaDados(ByVal iChave As Integer) Handles Me.carregaDados
        Dim drTipoPA As DataRow
        Try

            If conversao.nuloParaZero(MyBase.chave) <> 0 Then
                drTipoPA = Me.objTIpoPA.selecionarDadosTipoPA(Me.chave)

                If Not IsNothing(drTipoPA) Then
                    With drTipoPA
                        Me.txtCodigo.Text = conversao.nuloParaVazio(.Item("codTipoPA"))
                        Me.txtDescricao.Text = conversao.nuloParaVazio(.Item("descTipoPA"))
                        Me.chkEspComplemento.Checked = conversao.toBoolean(.Item("espComplemento"))
                    End With
                Else
                    MessageBox.Show("Dados do tipo de ponto de atendimento não encontrados.", Me.Text, MessageBoxButtons.OK, MessageBoxIcon.Information)
                End If
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try


    End Sub

    Private Sub frmTipoPA_excluir(ByRef bCancel As Boolean) Handles Me.excluir

        Try
            bCancel = True
            If Me.objTIpoPA.excluirTipoPA(Me.chave) Then
                bCancel = False
            End If

        Catch ex As Exception

            MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try


    End Sub

    Private Sub frmTipoPA_gravar(ByRef bCancel As Boolean) Handles Me.gravar

        Try
            bCancel = True

            If Me.objTIpoPA.gravarTipoPA(Me.chave,
                                        Me.txtDescricao.Text,
                                        Me.chkEspComplemento.Checked) Then
                bCancel = False
                Me.chave = Me.objTIpoPA.CodTipoPA

            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try


    End Sub

    Private Sub frmRepresentantes_limpaCampo() Handles Me.limpaCampo

        Me.limpaCampos(Me)

    End Sub

    Private Sub btnSelecionarC_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSelecionarTipoPA.Click
        Dim sSql As String
        Dim frmDialogo As New frmPesquisa

        Try
            sSql = Me.objTIpoPA.sqlConsulta()

            With frmDialogo
                .Sql = sSql
                .Titulo = "Pesquisar Tipo de Ponto de Atendimento"
                .CarregaTela(Nothing)
                If .DT.Rows.Count > 0 Then
                    .ShowDialog()
                    If (.DialogResult = Windows.Forms.DialogResult.OK) Then
                        Me.chave = conversao.toInt32(.ID)
                    End If
                Else
                    MsgBox("Registro não encontrado", MsgBoxStyle.Exclamation, Me.Text)
                    Exit Sub
                End If
            End With

        Catch ex As Exception
            MsgBox(ex.Message, MsgBoxStyle.Critical, Application.ProductName)
        End Try
    End Sub

    Private Sub txtCodigo_Leave(ByVal sender As Object, ByVal e As System.EventArgs) Handles txtCodigo.Leave

        Try

            If Not String.IsNullOrEmpty(Me.txtCodigo.Text) Then
                Me.chave = conversao.nuloParaZero(Me.txtCodigo.Text)
            End If

        Catch ex As Exception
            MessageBox.Show(ex.Message, Application.ProductName, MessageBoxButtons.OK, MessageBoxIcon.Error)
        End Try
    End Sub


#End Region


End Class
